package logic

import (
	mysql2 "camera/B/Rpc/model/mysql"
	"context"
	"fmt"

	"camera/B/Rpc/camera"
	"camera/B/Rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderListLogic {
	return &OrderListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderListLogic) OrderList(in *camera.OrderListRequest) (*camera.OrderListResponse, error) {
	// todo: add your logic here and delete this line
	o := mysql2.Order{}
	order, err := o.GetOrder(int(in.Page), int(in.PageSize))
	if err != nil {
		return nil, fmt.Errorf("查询失败")
	}
	var orders []*camera.OrderList
	for _, good := range order {
		orders = append(orders, &camera.OrderList{
			UserId:      int64(good.UserId),
			GoodId:      int64(good.GoodId),
			OrderSn:     good.OrderSn,
			Amount:      float32(good.Amount),
			GoodTitle:   good.GoodTitle,
			GoodImage:   good.GoodImage,
			OrderStatus: int64(good.OrderStatus),
			Payment:     int64(good.Payment),
		})
	}
	return &camera.OrderListResponse{
		OrderList: orders,
	}, nil
}
